package com.cloudbroker.bcs.platform.ltb.configure.define.parser;

import com.cloudbroker.bcs.platform.ltb.configure.define.element.HTMLFragment;
import com.cloudbroker.bcs.platform.ltb.configure.define.element.Property;
import org.dom4j.Element;

public class PropertyParser extends AbstractHTMLFragmentParser<Property> {
    
    public PropertyParser(ConfigureParser configureParser) {
        super(configureParser);
    }
    
    @Override
    public String parseFor() {
        return "property";
    }
    
    @Override
    public Property parseHTMLFragment(Element element, HTMLFragment<?, ?> contextFragment) {
        Property property = new Property();
        property = parseForAbstractHTMLFragment(property, element);
        
        String defaultValue = element.attributeValue("default");
        if (null != defaultValue) {
            property.setDefaultValue(defaultValue);
        }
        
        String description = element.attributeValue("description");
        if (null != description) {
            property.setDescription(description);
        }

        String type = element.attributeValue("type");
        if (null != type && "password".equalsIgnoreCase(type)) {
            property.setType(type);
        }
        
        property.setDataStore(configureParser.getDataStore());
        
        configureParser.parseChildElements(property, element);
        
        return property;
    }
    
}
